package com.tang.model.composite.transparent;


import java.util.ArrayList;
import java.util.List;

/**
 * @Author tangyuan2meicloud.com
 * @DATE 2021/8/22 21:48
 * @Desc
 * @Remarks
 */
public class CoursePackage extends CourseCompnent {

    private List<CourseCompnent> compnents;
    private String name;
    private Integer level;

    public CoursePackage(String name, Integer level) {
        this.compnents = new ArrayList<CourseCompnent>();
        this.name = name;
        this.level = level;
    }

    @Override
    public void addChild(CourseCompnent courseCompnent) {
        compnents.add(courseCompnent);
    }

    @Override
    public void removeChild(CourseCompnent courseCompnent) {
        compnents.remove(courseCompnent);
    }

    @Override
    public String getName() {
        return this.name;
    }

    @Override
    public void print() {
        System.out.println(name);
        for (CourseCompnent courseCompnent : compnents) {
            if (this.level != null) {
                for (int i = 0; i < level; i++) {
                    System.out.print("  ");
                }

                for (int i = 0; i < level; i++) {
                    if (i == 0) {
                        System.out.print("+");
                    }
                    System.out.print("--");
                }
            }
            courseCompnent.print();
        }
    }
}
